//
//  XJSureOrderBottomView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/12.
//  Copyright © 2018年 Tzyang. All rights reserved.
//  h : 50

#import "XJSureOrderBottomView.h"
@interface XJSureOrderBottomView()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UILabel *yinfuTipLb;
@property(nonatomic, strong) UILabel *totaoPriceLb;
@property(nonatomic, strong) UIButton *buyButton;

@end

@implementation XJSureOrderBottomView

#pragma mark - 1.init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}


- (void)setupView {
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.yinfuTipLb];
    [self.bgView addSubview:self.totaoPriceLb];
    [self.bgView addSubview:self.buyButton];
}

#pragma mark - 2.lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
    }
    return _bgView;
}
- (UILabel *)yinfuTipLb {
    if (!_yinfuTipLb) {
        _yinfuTipLb = [UILabel new];
        _yinfuTipLb.textColor = [UIColor lightGrayColor];
        _yinfuTipLb.text = @"应付";
        _yinfuTipLb.font = XJFONTSET_R(14.0);
    }
    return _yinfuTipLb;
}
- (UILabel *)totaoPriceLb {
    if (!_totaoPriceLb) {
        _totaoPriceLb = [UILabel new];
        _totaoPriceLb.text = @"￥66.0";
        _totaoPriceLb.textColor = [UIColor redColor];
    }
    return _totaoPriceLb;
}
- (UIButton *)buyButton {
    if (!_buyButton) {
        _buyButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_buyButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_buyButton setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
        [_buyButton setTitle:@"立即下单" forState:(UIControlStateNormal)];
        
        _buyButton.backgroundColor = XJCOLOR_RGB(255, 218, 67);
        _buyButton.layer.masksToBounds = YES;
        _buyButton.layer.cornerRadius = 10;
        [_buyButton addTarget:self action:@selector(buyButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
        
    }
    return _buyButton;
    
}
#pragma mark - 3.layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    CGFloat k15 = 15.0;
    [self.yinfuTipLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(k15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(60, 30));
    }];
    
    [self.totaoPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.yinfuTipLb.mas_right).offset(-k15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 30));
    }];
    [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.bgView.mas_right).offset(-k15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
}


#pragma mark - 4.action
- (void)buyButtonAction {
//    XJLog(@"立即下单");
    if (self.buyBtnBlock) {
        self.buyBtnBlock();
    }
}

#pragma mark - 5.  configure
- (void)configureSureOrderBottomViewWithTotalPrice:(NSString *)totalPrice {
    
    self.totaoPriceLb.text = [NSString stringWithFormat:@"￥%.1f",[totalPrice floatValue]];
    
}

@end
